﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNet.SignalR;

namespace SimpleTaskSystem.WebSpaAngular.Core
{
    public class ChatHub : Hub
    {
        
       
        public void Send(string name, string message)
        {

            // Call the addNewMessageToPage method to update clients.

            Clients.All.addNewMessageToPage(name, message);

        }
        public void Send(dynamic msg)
        {
            Clients.All.addNewMessageToPage(msg);

        }
        public void Update(dynamic msg)
        {

            Clients.All.UpdateMessageToPage(msg);

        }

        /// <summary>
        /// 连接
        /// </summary>
        /// <returns></returns>
        public override System.Threading.Tasks.Task OnConnected()
        {
            Groups.Add(Context.ConnectionId, Context.User.Identity.Name);
            return base.OnConnected();
        }
        /// <summary>
        /// 重新连接
        /// </summary>
        /// <returns></returns>
        public override System.Threading.Tasks.Task OnReconnected()
        {
            Groups.Add(Context.ConnectionId, Context.User.Identity.Name);
            return base.OnReconnected();
        }

        /// <summary>
        /// 断开连接
        /// </summary>
        /// <param name="stopCalled"></param>
        /// <returns></returns>
        public override System.Threading.Tasks.Task OnDisconnected(bool stopCalled)
        {
            Groups.Remove(Context.ConnectionId, Context.User.Identity.Name);
            return base.OnDisconnected(stopCalled);
        }
    }
}